home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0015 / flicker / main.c < prev    next >
C/C++ Source or Header  |  1997-04-16  |  11KB  |  623 lines

  1. /* :ts=3 */
  2. #include <osbind.h>
  3. #include <gemdefs.h>
  4. #include "flicker.h"
  5.  
  6. extern Pull root_pull;
  7. extern Pull vdraw_pull, nozero_pull, filled_pull, degas_pull, zoom_pull;
  8. extern drizzle(), draw(), draw_box(), draw_line(), rays(), flood(),
  9.     draw_circle(), spray(), draw_lines(), draw_polygon();
  10.  
  11. WORD ccolor = 2;
  12. WORD nozero_flag = 1;
  13. WORD filled_flag = 1;
  14. WORD degas = 1;
  15. WORD use_brush_cursor = 1;
  16. WORD zoom_flag = 0;    /* are we in zoom mode? */
  17. WORD zoomx, zoomy;    /* offset of zoom area into full screen */
  18. WORD zscale_cursor;
  19. Vector pen_tool = draw;
  20.  
  21. char dot_neo[] = "NEO";
  22. char dot_pi1[] = "PI1";
  23. char dot_cel[] = "CEL";
  24. char dot_col[] = "COL";
  25. char dot_seq[] = "SEQ";
  26.  
  27.  
  28. main(argc, argv)
  29. int argc;
  30. char *argv[];
  31. {
  32. int i;
  33. unsigned char menuix, selix;
  34.  
  35.  
  36. if ((i = init_sys())<0)
  37.     {
  38.     uninit_sys();
  39.     exit(i);
  40.     }
  41. hide_mouse();
  42. clear_screen();
  43. show_mouse();
  44. for (;;)
  45.     {
  46.     check_input();
  47.     update_zoom();
  48.     if (key_hit)
  49.         do_key();
  50.     else if (EDN)
  51.         {
  52.         if (PDN)
  53.             (*pen_tool)();
  54.         else if (RDN)
  55.             {
  56.             if ((i = pull(&root_pull)) >= 0)
  57.                 {
  58.                 menuix = i>>8;
  59.                 selix = i&0xff;
  60.                 switch (menuix)
  61.                     {
  62.                     case 0:    /* file menu */
  63.                         switch (selix)
  64.                             {
  65.                             case 0:
  66.                                 top_line("Flicker 0.2 Copyright 1987 Dancing Flame");
  67.                                 break;
  68.                             case 1:
  69.                                 break;
  70.                             case 2:
  71.                                 go_lpic();
  72.                                 break;
  73.                             case 3:
  74.                                 go_spic();
  75.                                 break;
  76.                             case 4:
  77.                                 go_lcel();
  78.                                 break;
  79.                             case 5:
  80.                                 go_scel();
  81.                                 break;
  82.                             case 6:
  83.                                 go_lseq();
  84.                                 break;
  85.                             case 7:
  86.                                 go_sseq();
  87.                                 break;
  88.                             case 8:
  89.                                 go_lcol();
  90.                                 break;
  91.                             case 9:
  92.                                 go_scol();
  93.                                 break;
  94.                             case 10:
  95.                                 go_byebye();
  96.                                 break;
  97.                             }
  98.                         break;
  99.                     case 1:    /* Edit Menu */
  100.                         switch (selix)
  101.                             {
  102.                             case 0:
  103.                                 swap_undo();
  104.                                 break;
  105.                             case 1:
  106.                                 blue_pic();
  107.                                 break;
  108.                             case 2:
  109.                                 unblue_pic();
  110.                                 break;
  111.                             case 3:
  112.                                 clear_pic();
  113.                                 break;
  114.                             case 4:
  115.                                 clear_seq();
  116.                                 break;
  117.                             case 6:
  118.                                 cut_clip();
  119.                                 break;
  120.                             case 7:
  121.                                 clip_clip();
  122.                                 break;
  123.                             case 8:
  124.                                 paste_clip();
  125.                                 break;
  126.                             case 9:
  127.                                 cfit_clip();
  128.                                 break;
  129.                             }
  130.                         break;
  131.                     case 2:        /* Draw Menu */
  132.                         unxmenu(&vdraw_pull);
  133.                         xone(&vdraw_pull, selix);
  134.                         switch (selix)
  135.                             {
  136.                             case 0:
  137.                                 pen_tool = draw;
  138.                                 use_brush_cursor = 1;
  139.                                 break;
  140.                             case 1:
  141.                                 pen_tool = drizzle;
  142.                                 use_brush_cursor = 1;
  143.                                 break;
  144.                             case 2:
  145.                                 pen_tool = spray;
  146.                                 use_brush_cursor = 1;
  147.                                 break;
  148.                             case 3:
  149.                                 pen_tool = flood;
  150.                                 use_brush_cursor = 0;
  151.                                 break;
  152.                             case 4:
  153.                                 pen_tool = draw_line;
  154.                                 use_brush_cursor = 0;
  155.                                 break;
  156.                             case 5:
  157.                                 pen_tool = draw_lines;
  158.                                 use_brush_cursor = 0;
  159.                                 break;
  160.                             case 6:
  161.                                 pen_tool = draw_polygon;
  162.                                 use_brush_cursor = 0;
  163.                                 break;
  164.                             case 7:
  165.                                 pen_tool = rays;
  166.                                 use_brush_cursor = 0;
  167.                                 break;
  168.                             case 8:
  169.                                 pen_tool = draw_circle;
  170.                                 use_brush_cursor = 1;
  171.                                 break;
  172.                             case 9:
  173.                                 pen_tool = draw_box;
  174.                                 use_brush_cursor = 0;
  175.                                 break;
  176.                             }
  177.                         pick_cursor();    /* based on use_brush_cursor */
  178.                         break;
  179.                     case 3:
  180.                         switch (selix)
  181.                             {
  182.                             case 0:
  183.                                 show_status();
  184.                                 break;
  185.                             case 1:
  186.                                 nozero_flag = !nozero_flag;
  187.                                 xonflag(&nozero_pull, nozero_flag);
  188.                                 break;
  189.                             case 2:
  190.                                 filled_flag = !filled_flag;
  191.                                 xonflag(&filled_pull, filled_flag);
  192.                                 break;
  193.                             case 3:
  194.                                 xonflag(°as_pull, degas);
  195.                                 degas = !degas;
  196.                                 break;
  197.                             case 4:
  198.                                 dozoom();
  199.                                 break;
  200.                             }
  201.                         break;
  202.                     case 4:    /* Frames menu */
  203.                         switch (selix)
  204.                             {
  205.                             case 0:
  206.                                 next_frame();
  207.                                 break;
  208.                             case 1:
  209.                                 last_frame();
  210.                                 break;
  211.                             case 2:
  212.                                 start_frame();
  213.                                 break;
  214.                             case 3:
  215.                                 end_frame();
  216.                                 break;
  217.                             case 4:
  218.                                 mnext_frame();
  219.                                 break;
  220.                             case 5:
  221.                                 mlast_frame();
  222.                                 break;
  223.                             case 6:
  224.                                 delete_frame();
  225.                                 break;
  226.                             case 8:
  227.                                 play_forwards();
  228.                                 break;
  229.                             case 9:
  230.                                 play_backwards();
  231.                                 break;
  232.                             case 10:
  233.                                 play_slowly();
  234.                                 break;
  235.                             case 11:
  236.                                 play_fast();
  237.                                 break;
  238.                             }
  239.                         break;
  240.                     case 5:
  241.                         set_brush(selix);    /* set brush for system */
  242.                         hide_mouse();        /* and force flicker mouse so immediately*/
  243.                         show_mouse();        /* see new brush */
  244.                         break;
  245.                     case 6:
  246.                         ccolor = selix;
  247.                         break;
  248.                     }
  249.                 }
  250.             }
  251.         }
  252.     }
  253. }
  254.  
  255. char *title;
  256.  
  257. char *
  258. pic_suffix()
  259. {
  260. return( degas ? dot_pi1 : dot_neo);
  261. }
  262.  
  263. go_lpic()
  264. {
  265. save_undo();
  266. set_for_gem();
  267. gmessage("Load Picture");
  268. if ((title = get_fname(pic_suffix())) != NULL)
  269.     load_pic(title);
  270. set_for_jim();
  271. see_screen_ix();
  272. }
  273.  
  274. go_spic()
  275. {
  276. save_undo();
  277. set_for_gem();
  278. gmessage("Save Picture");
  279. if ((title = get_fname(pic_suffix())) != NULL)
  280.     {
  281.     save_pic(title);
  282.     }
  283. set_for_jim();
  284. see_screen_ix();
  285. }
  286.  
  287. go_lcel()
  288. {
  289. save_undo();
  290. set_for_gem();
  291. gmessage("Load Cel");
  292. if ((title = get_fname(dot_cel)) != NULL)
  293.     load_cel(title);
  294. set_for_jim();
  295. see_screen_ix();
  296. if (clipping != NULL)
  297.     rub_paste(0, 0);    /* flash cel up on screen a second so user knows 
  298.                                 it's really loaded */
  299. wait_a_jiffy(20);
  300. see_screen_ix();
  301. }
  302.  
  303. go_scel()
  304. {
  305. if (  clipping == NULL)
  306.     {
  307.     top_line("No Clip to Save!");
  308.     return;
  309.     }
  310. save_undo();
  311. set_for_gem();
  312. gmessage("Save Cel");
  313. if ((title = get_fname(dot_cel)) != NULL)
  314.     {
  315.     save_cel(title);
  316.     }
  317. set_for_jim();
  318. see_screen_ix();
  319. }
  320.  
  321. go_lcol()
  322. {
  323. save_undo();
  324. set_for_gem();
  325. gmessage("Load Colors");
  326. if ((title = get_fname(dot_col)) != NULL)
  327.     load_col(title);
  328. set_for_jim();
  329. see_screen_ix();
  330. }
  331.  
  332. go_scol()
  333. {
  334. save_undo();
  335. set_for_gem();
  336. gmessage("Save Colors");
  337. if ((title = get_fname(dot_col)) != NULL)
  338.     save_col(title);
  339. set_for_jim();
  340. see_screen_ix();
  341. }
  342.  
  343.  
  344. go_sseq()
  345. {
  346. save_undo();
  347. set_for_gem();
  348. gmessage("Save Sequence");
  349. if ((title = get_fname(dot_seq)) != NULL)
  350.     save_seq(title);
  351. set_for_jim();
  352. see_screen_ix();
  353. }
  354.  
  355. go_lseq()
  356. {
  357. save_undo();
  358. set_for_gem();
  359. gmessage("Load Sequence");
  360. if ((title = get_fname(dot_seq)) != NULL)
  361.     load_seq(title);
  362. set_for_jim();
  363. see_screen_ix();
  364. }
  365.  
  366.  
  367. do_key()
  368. {
  369. register unsigned char c, d;
  370.  
  371. c = key_in;
  372. d = key_in>>8;
  373. switch(c)
  374.     {
  375.     case 0:
  376.         switch (d)
  377.             {
  378.             case 0x3b:    /* F1 */
  379.                 cut_clip();
  380.                 break;
  381.             case 0x3c:    /* F2 */
  382.                 clip_clip();
  383.                 break;
  384.             case 0x3d:    /* F3 */
  385.                 paste_clip();
  386.                 break;
  387.             case 0x3e:    /* F4 */
  388.                 cfit_clip();
  389.                 break;
  390.             case 0x41:    /* F7 */
  391.                 play_fast();
  392.                 break;
  393.             case 0x42:    /* F8 */
  394.                 play_slowly();
  395.                 break;
  396.             case 0x43:    /* F9 */
  397.                 play_backwards();
  398.                 break;
  399.             case 0x44:    /* F10 */
  400.                 play_forwards();
  401.                 break;
  402.             case 0x4b:    /* left arrow */
  403.                 last_frame();
  404.                 break;
  405.             case 0x4d:    /* right arrow */
  406.                 next_frame();
  407.                 break;
  408.             case 0x48:    /* up arrow */
  409.                 start_frame();
  410.                 break;
  411.             case 0x50: /* down arrow */
  412.                 end_frame();
  413.                 break;
  414.             case 0x61: /* undo */
  415.                 swap_undo();
  416.                 break;
  417.             case 0x52: /* insert */
  418.                 mlast_frame();
  419.                 break;
  420.             case 0x47: /* clr/home */
  421.                 mnext_frame();
  422.                 break;
  423.             }
  424.         break;
  425.     case 'c':
  426.         hide_mouse();
  427.         ccolor = getdot(mouse_x, mouse_y);
  428.         show_mouse();
  429.         break;
  430.     case 'q':
  431.         go_byebye();
  432.         break;
  433.     case ' ':
  434.         show_status();
  435.         break;
  436.     case '\b': /* backspace */
  437.         clear_pic();
  438.         break;
  439.     case '(':
  440.         blue_pic();
  441.         break;
  442.     case ')':
  443.         unblue_pic();
  444.         break;
  445.     case 0x7f:    /* delete */
  446.         delete_frame();
  447.         break;
  448.     case 'z':
  449.         dozoom();
  450.         break;
  451.     }
  452. }
  453.  
  454. show_status()
  455. {
  456. char buf[48];
  457.  
  458. sprintf(buf, "%d of %d | %ld free of %ld", screen_ix+1, screen_ct,
  459.     mem_free, cel_mem_alloc);
  460. top_line(buf);
  461. }
  462.  
  463. save_undo()
  464. {
  465. hide_mouse();
  466. copy_screen( cscreen, screens[screen_ix]);
  467. show_mouse();
  468. }
  469.  
  470. swap_undo()
  471. {
  472. hide_mouse();
  473. exchange_screen(cscreen, screens[screen_ix]);
  474. show_mouse();
  475. if (zoom_flag)
  476.     zbuf_to_screen();
  477. }
  478.  
  479. unundo()
  480. {
  481. copy_screen( screens[screen_ix], cscreen);
  482. }
  483.  
  484. see_screen_ix()
  485. {
  486. hide_mouse();
  487. unundo();
  488. show_mouse();
  489. if (zoom_flag)
  490.     zbuf_to_screen();
  491. }
  492.  
  493. clear_pic()
  494. {
  495. save_undo();
  496. hide_mouse();
  497. clear_screen();
  498. show_mouse();
  499. if (zoom_flag)
  500.     zbuf_to_screen();
  501. }
  502.  
  503. clear_seq()
  504. {
  505. int i;
  506.  
  507. for (i=1; i<screen_ct; i++)
  508.     {
  509.     mfree(screens[i], 32000);
  510.     screens[i] = NULL;
  511.     }
  512. screen_ix = 0;
  513. screen_ct = 1;
  514. hide_mouse();
  515. clear_screen();
  516. show_mouse();
  517. save_undo();
  518. if (zoom_flag)
  519.     zbuf_to_screen();
  520. }
  521.  
  522. blue_pic()
  523. {
  524. save_undo();
  525. undo_to_buf();
  526. hide_mouse();
  527. b_pic();
  528. show_mouse();
  529. if (zoom_flag)
  530.     zbuf_to_screen();
  531. }
  532.  
  533. unblue_pic()
  534. {
  535. save_undo();
  536. hide_mouse();
  537. ub_pic();
  538. show_mouse();
  539. if (zoom_flag)
  540.     zbuf_to_screen();
  541. }
  542.  
  543.  
  544. go_byebye()
  545. {
  546. hide_mouse();
  547. draw_on_screen();
  548. uninit_sys();
  549. exit(0);
  550. }
  551.  
  552.  
  553. extern long time_peek();
  554.  
  555. rub_zoom()
  556. {
  557. draw_frame(white, zoomx, zoomy, 
  558.     zoomx+XMAX/4-1, zoomy+YMAX/4-1);
  559. }
  560.  
  561. clip_zoomxy(x, y)
  562. WORD x, y;
  563. {
  564. zoomx = x-XMAX/8+8;    /* mouse in middle of zoom buffer */
  565. zoomx &= 0xfff0;    /* zoomx must be on a word boundary */
  566. if (zoomx > XMAX - XMAX/4)
  567.     zoomx = XMAX - XMAX/4;        /* don't let zoom go off screen */
  568. if (zoomx < 0)
  569.     zoomx = 0;
  570. zoomy = y-YMAX/8;    /* mouse in middle of zoom buffer */
  571. if (zoomy > YMAX - YMAX/4)
  572.     zoomy = YMAX - YMAX/4;        /* don't let zoom go off screen */
  573. if (zoomy < 0)
  574.     zoomy = 0;
  575. }
  576.  
  577.  
  578. dozoom()    /* toggle zoom state, rub around the zoom box if turning on*/
  579. {
  580. if (!zoom_flag)
  581.     {
  582.     save_undo();
  583.     undo_to_buf();
  584.     hide_mouse();
  585.     draw_on_buffer();
  586.     clip_zoomxy(mouse_x, mouse_y);
  587.     rub_zoom();
  588.     show_mouse();
  589.     see_buffer();
  590.     for (;;)
  591.         {
  592.         check_input();
  593.         if (mouse_moved)
  594.             {
  595.             hide_mouse();
  596.             unundo();
  597.             clip_zoomxy(mouse_x, mouse_y);
  598.             rub_zoom();
  599.             show_mouse();
  600.             see_buffer();
  601.             }
  602.         if (PDN)
  603.             break;
  604.         }
  605.     hide_mouse();
  606.     unundo();
  607.     zscale_cursor = zoom_flag = 1;
  608.     show_mouse();
  609.     zbuf_to_screen();
  610.     wait_penup();
  611.     }
  612. else
  613.     {
  614.     hide_mouse();
  615.     draw_on_screen();
  616.     buf_to_screen();
  617.     zscale_cursor = zoom_flag = 0;
  618.     show_mouse();
  619.     }
  620. xonflag(&zoom_pull, zoom_flag);
  621. }
  622.  
  623.